package aleksandar.djuric.gui;

import java.awt.Color;

import javax.swing.JEditorPane;



public class ColorPane extends JEditorPane
{
	private static final long serialVersionUID = 1L;
	
	public ColorPane()
	{
		super();
		this.setContentType("text/html");
//		this.setFont(new Font(
//				getFont().getName(), Font.BOLD, getFont().getSize()));
	}
	
	@Override
	public void setText(String t) {
		super.setText("<b>" + t + "</b>");
		setCaretPosition(0);
	}
	
	public void setText(Color c, String s)
	{
		setText("<p style=\"color:" +
					"#" + 
					Integer.toHexString(c.getRGB()).substring(2) +
					"\">" + s + "</p>");
	}

	public synchronized void append(Color c, String s) { 
		
			String tmp = getText();
			int start=0, end=0;
			start = tmp.indexOf("<body>") + 6;
			end = tmp.indexOf("</body>");
			tmp = tmp.substring(start, end);
			String p = "<p>";
			if(c != null)
				p = "<p style=\"color:" +
						"#" + 
						Integer.toHexString(c.getRGB()).substring(2) +
						"\">";
			setText(tmp + p + "<b>" + s + "</b></p>");
	}
}
